package com.lili.price;

/**
 * @Auther: 李 力
 * @Date: 2024/8/24
 * @Description: PACKAGE_NAME
 * @version: 1.0
 */
public class LeetCode121 {
    /*
     * i天买入   j天卖出
     *
     * */
    public static int maxProfit(int[] prices) {
        int i = 0;
        int j = 1;
        int maxNum = 0;
        while (i < prices.length) {
            if (prices[j] - prices[i] > 0) {
                //涨了
                maxNum = Math.max(maxNum, prices[j] - prices[i]);
                j++;
            } else {
                i = j;
                j++;
            }
        }
        return maxNum;
    }
}
